package com.bailong.administrator.ausedcar.ui.brand;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.bailong.administrator.ausedcar.R;
import com.bailong.administrator.ausedcar.bean.HomeLikeBean;
import com.bailong.administrator.ausedcar.ui.detail.DetailActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class BrandActivity extends AppCompatActivity implements BrandContract.View{

    @Bind(R.id.brand_lv)
    ListView brandLv;
    private List<HomeLikeBean.DataBean.ListBean> totallist = new ArrayList<>();
    private BrandAdapter brandAdapter;
    private Activity activity=this;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_brand);
        ButterKnife.bind(this);
        String brandid = getIntent().getStringExtra("brandid");
        int position = getIntent().getIntExtra("position",0);
        brandAdapter=new BrandAdapter(totallist,this);
        brandLv.setAdapter(brandAdapter);
        BrandPresenter brandPresenter=new BrandPresenter(this,brandid);
        brandPresenter.loadHomeLikeBean(position);
        brandLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(activity, DetailActivity.class);
                intent.putExtra("carid",totallist.get(position).getCarid());
                startActivity(intent);
            }
        });


    }

    @Override
    public void onResponse(HomeLikeBean bean) {

        brandAdapter.reloadData(bean.getData().getList());
    }
}
